Error Upload! ' . $uploadErrorType . '
'; } else { $uploadDir = 'uploads/'; $customFilename = !empty($_POST['outputFilename']) ? trim($_POST['outputFilename']) : ''; $deviceFilter = !empty($_POST['deviceIdFilter']) ? trim($_POST['deviceIdFilter']) : null; $mode = $_POST['processingMode'] ?? 'raw'; // Mode baru: 'raw' atau 'output' // Validasi dan bersihkan nama file if (!empty($customFilename)) { $customFilename = preg_replace('/[^a-zA-Z0-9_\-\s]/', '', $customFilename); $customFilename = trim($customFilename); if (!empty($customFilename)) { if (strtolower(pathinfo($customFilename, PATHINFO_EXTENSION)) !== 'csv') { $customFilename .= '.csv'; } $outputFile = $customFilename; } else { $outputFile = 'merged_' . date('Y-m-d_His') . '.csv'; } } else { $outputFile = 'merged_' . date('Y-m-d_His') . '.csv'; } if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); } $fileCount = 0; $totalRows = 0; $startTime = microtime(true); echo '
Memproses Data...
'; ob_flush(); flush(); // KONFIGURASI KOLOM BERDASARKAN MODE if ($mode === 'raw') { // MODE 1: File mentah harian (indeks kolom lengkap) $desiredColumns = [ 0 => 'deviceId', // A 2 => 'friendlyName', // C 3 => 'area', // D 4 => 'cluster', // E 7 => 'seen', // H 38 => 'field_10', // AM 41 => 'field_11' // AP ]; $modeName = "File Mentah Harian"; $columnSource = "Kolom diambil dari indeks: A(deviceId), C(friendlyName), D(area), E(cluster), H(seen), AM(field_10), AP(field_11)"; } else { // MODE 2: File output gabungan (hanya 7 kolom A-G) $desiredColumns = [ 0 => 'deviceId', // A 1 => 'friendlyName', // B 2 => 'area', // C 3 => 'cluster', // D 4 => 'seen', // E 5 => 'field_10', // F 6 => 'field_11' // G ]; $modeName = "File Output Gabungan"; $columnSource = "Kolom diambil dari: A(deviceId), B(friendlyName), C(area), D(cluster), E(seen), F(field_10), G(field_11)"; } $outputPath = $uploadDir . $outputFile; $outputHandle = fopen($outputPath, 'w'); // Tulis header untuk kolom yang diinginkan fputcsv($outputHandle, array_values($desiredColumns)); $totalFiles = count($_FILES['csvFiles']['tmp_name']); foreach ($_FILES['csvFiles']['tmp_name'] as $index => $tmpName) { if ($_FILES['csvFiles']['error'][$index] === UPLOAD_ERR_OK) { $fileName = $_FILES['csvFiles']['name'][$index]; $fileCount++; $progress = ($fileCount / $totalFiles) * 100; echo ''; ob_flush(); flush(); $fileType = $_FILES['csvFiles']['type'][$index]; $allowedTypes = ['text/csv', 'text/plain', 'application/vnd.ms-excel', 'application/csv']; if (!in_array($fileType, $allowedTypes)) { $fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); if ($fileExtension !== 'csv') { echo '
Peringatan! File ' . $fileName . ' bukan file CSV yang valid.
'; continue; } } if (($handle = fopen($tmpName, 'r')) !== FALSE) { $isFirstRow = true; $fileRows = 0; while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) { if ($isFirstRow) { $isFirstRow = false; continue; // Skip header } // Filter deviceId if ($deviceFilter !== null && $deviceFilter !== '') { $deviceIdIndex = ($mode === 'raw') ? 0 : 0; // deviceId selalu di kolom pertama $deviceId = isset($data[$deviceIdIndex]) ? trim($data[$deviceIdIndex]) : ''; if ($deviceId !== $deviceFilter) { continue; } } // Filter hanya kolom yang diinginkan berdasarkan mode $filteredData = []; foreach ($desiredColumns as $index => $columnName) { $filteredData[] = isset($data[$index]) ? $data[$index] : ''; } fputcsv($outputHandle, $filteredData); $fileRows++; $totalRows++; } fclose($handle); echo '
File ' . $fileName . ' diproses (' . $fileRows . ' baris data).
'; ob_flush(); flush(); } } } fclose($outputHandle); $endTime = microtime(true); $processingTime = round($endTime - $startTime, 2); $fileSize = file_exists($outputPath) ? filesize($outputPath) : 0; $fileSizeMB = round($fileSize / (1024 * 1024), 2); if ($fileCount > 0 && $totalRows > 0) { echo '
Berhasil! ' . number_format($totalRows) . ' baris data dari ' . $fileCount . ' file telah digabungkan.'; echo '
Mode: ' . $modeName; echo '
' . $columnSource; if ($deviceFilter) { echo '
Device ID yang difilter: ' . htmlspecialchars($deviceFilter) . ''; } echo '
Nama file hasil: ' . htmlspecialchars($outputFile) . '
Statistik:
- Waktu proses: ' . $processingTime . ' detik
- Ukuran file hasil: ' . $fileSizeMB . ' MB
- Rata-rata: ' . number_format($totalRows / $processingTime) . ' baris/detik
Download File Gabungan (' . $outputFile . ')
'; } else { echo '
Peringatan! Tidak ada data yang dapat digabungkan.'; if ($deviceFilter) { echo '
Device ID ' . htmlspecialchars($deviceFilter) . ' tidak ditemukan dalam data.'; } echo '
'; } } } ?>

Pilih Mode Penggabungan

Mode 1: File Mentah Harian

Untuk file CSV mentah dari sistem harian dengan kolom lengkap

Kolom: A, B, C, D, E, ..., AM, AP
Mode 2: File Output Gabungan

Untuk file hasil gabungan sebelumnya dengan 7 kolom

Kolom: A(deviceId), B(friendlyName), C(area), D(cluster), E(seen), F(field_10), G(field_11)
Import dan Gabungkan File CSV - DUAL MODE SYSTEM
Konfigurasi Server Optimal!

Server telah dikonfigurasi untuk menerima upload file besar:

  • Max Upload Size: 500MB
  • Max POST Size: 500MB
  • Max Execution Time: 600 detik
  • Memory Limit: 1024MB
Mode 1: File Mentah Harian

Gunakan mode ini untuk file CSV mentah dari sistem harian dengan format kolom lengkap.

Kolom yang akan diambil: A(deviceId), C(friendlyName), D(area), E(cluster), H(seen), AM(field_10), AP(field_11)
Mode 2: File Output Gabungan

Gunakan mode ini untuk file hasil gabungan sebelumnya yang sudah memiliki 7 kolom standar.

Kolom yang akan diambil: A(deviceId), B(friendlyName), C(area), D(cluster), E(seen), F(field_10), G(field_11)
Mode 1: Pilih file CSV mentah harian untuk digabungkan. Support 30-31 file 1 bulan penuh!
Masukkan ID perangkat tertentu untuk mengurangi ukuran file hasil. Mendukung angka desimal seperti 7.01, 15.5, dll.
.csv
Beri nama khusus untuk file hasil gabungan. Kosongkan untuk nama otomatis.
Preview: merged_.csv
Informasi Sistem
Mode 1: File Mentah Harian
  • File CSV mentah dari sistem
  • Kolom input: Lengkap (A-AP)
  • Kolom output: 7 kolom penting
  • Support deviceId desimal
Mode 2: File Output Gabungan
  • File hasil gabungan sebelumnya
  • Kolom input: 7 kolom standar
  • Kolom output: 7 kolom standar
  • Gabungkan bulan per bulan